<?php 
if (!isset($_SESSION)) {
  session_start();
}
define("CCTRL", "register");
define("CCTRLNAME", "register");
define("TOKEN", "--");
include APPPATH . 'libraries/defu.php';
class register extends CI_Controller  {

        /**
        * Index Page for this controller.
        *
        * Maps to the following URL
        * 		http://example.com/index.php/welcome
        *	- or -  
        * 		http://example.com/index.php/welcome/index
        *	- or -
        * Since this controller is set as the default controller in 
        * config/routes.php, it's displayed at http://example.com/
        *
        * So any other public methods not prefixed with an underscore will
        * map to /index.php/welcome/<method_name>
        * @see http://codeigniter.com/user_guide/general/urls.html
        */
       protected $configs;
       function __construct()
        {
            parent::__construct();
            $this->load->helper('url');
            $this->load->model('backend/personal_model');
            $this->personal_model=new personal_model();
            $this->load->library('smarty3');
            $this->smarty=new CI_Smarty3();
            $this->smarty->error_reporting = E_ALL & ~E_NOTICE;
            if(!isset($_SESSION["ADP"][CCTRL]["display"]))$_SESSION["ADP"][CCTRL]["display"]=0;
        }
        function personal(){
            if(!isset($_SESSION["ADP"]["USER"])){
                $this->smarty->display("backend/00_login"); 
                return;
            }
            if(!checkAuthority(CCTRLNAME)){
                $this->smarty
                        ->assign('_SESSION', $_SESSION)
                        ->display("backend/00_accessdenied");
                return;
            }
            $this->smarty
                    ->assign('_SESSION', $_SESSION)
                    ->display("backend/".CCTRL."/personal");
        }
        function commercial(){
            if(!isset($_SESSION["ADP"]["USER"])){
                $this->smarty->display("backend/00_login"); 
                return;
            }
            if(!checkAuthority(CCTRLNAME)){
                $this->smarty
                        ->assign('_SESSION', $_SESSION)
                        ->display("backend/00_accessdenied");
                return;
            }
            $this->smarty
                    ->assign('_SESSION', $_SESSION)
                    ->display("backend/".CCTRL."/commercial");
        }
        function booktour(){
            if(!isset($_SESSION["ADP"]["USER"])){
                $this->smarty->display("backend/00_login"); 
                return;
            }
            if(!checkAuthority(CCTRLNAME)){
                $this->smarty
                        ->assign('_SESSION', $_SESSION)
                        ->display("backend/00_accessdenied");
                return;
            }
            $this->smarty
                    ->assign('_SESSION', $_SESSION)
                    ->display("backend/".CCTRL."/booktour");
        }
        function gridscript($type=""){
            //unset($_SESSION["ADP"][CCTRL."-JQX"]);
            if($type=="personal"){
                $this->load->model('colmod/personal_colmod');
                $this->colModel=new personal_colmod();
            }elseif($type=="commercial"){
                $this->load->model('colmod/commercial_colmod');
                $this->colModel=new commercial_colmod();
            }else{
                $this->load->model('colmod/book_colmod');
                $this->colModel=new book_colmod();
            }
            $colModel=$this->colModel->get();
                
            header("Content-type:text/javascript");
            $this->smarty
                    ->assign("colModel", $colModel)
                    ->assign("type", $type)
                    ->assign("display",$_SESSION["ADP"][CCTRL]["display"])
                    ->display("backend/00_base/grid_classic");
        }
        function handleEvent(){
            header("Content-type:text/javascript");
            $this->smarty
                    ->display("backend/".CCTRL."/handleEvent");
        }
        function binding($type=""){
            $data_rows=array();
            if($type=="personal"){
                $result=$this->personal_model->binding();
            }elseif($type=="commercial"){
                $result=$this->personal_model->binding_commercial();
            }else{
                $result=$this->personal_model->binding_book_tour();
            }
            $data[] = array(
                'TotalRows' => $result['total_rows'],
                'Rows' => $result['rows']
            );
            echo json_encode($data);
        }
        
}
?>
